
<template>
  <div id="upload_img_component">
    <div id="upload_img_component_sheet" class="mui-popover mui-popover-bottom mui-popover-action ">
      <!-- 可选择菜单 -->
      <ul class="mui-table-view">
        <li class="mui-table-view-cell" id="paizhao">
          <a href="#">拍照</a>
        </li>
        <li class="mui-table-view-cell" id="xiangce">
          <a href="#">相册</a>
        </li>
      </ul>
      <!-- 取消菜单 -->
      <ul class="mui-table-view">
        <li class="mui-table-view-cell">
          <a href="#sheet1"><b>取消</b></a>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>

  import ts from '../tools/UploadImg'
  export default {
    name:'upload_img_component',
    created(){

    },
    /*
          上传图片的类型 upload_img_type
        *     square-->社区广场 上传图片
        *     user-->用户头像 上传图片
        *     goods-->商品评论 上传图片
        *
        * */

    mounted(){

      let that = this;
      mui.plusReady(function () {
        ts.select_img('xiangce', function(path) {
          mui('#upload_img_component_sheet').popover('hide');
          mui.toast(path);
          console.log("相册选择上传成功");
          // commit 会默认提交两次
          // 生成时间戳，和随机数  用于判断是否是同一次提交
          let d  = new Date();
          let random = parseInt(Math.random()*1000000);
          let times = d.getTime();
          console.log(times+""+random);
          that.$store.commit("save_upload_img_url",{
            sign:times+""+random,
            path:path
          })

        });
        ts.get_img('paizhao', function(path) {
          mui('#upload_img_component_sheet').popover('hide');
          mui.toast(path);
          console.log("拍照上传成功");
          // commit 会默认提交两次
          // 生成时间戳，和随机数  用于判断是否是同一次提交
          let d  = new Date();
          let random = parseInt(Math.random()*1000000);
          let times = d.getTime();
          console.log(times+""+random);
          that.$store.commit("save_upload_img_url",{
            sign:times+""+random,
            path:path
          })

        });
      })

    }
  }

</script>
<style scoped lang="less">
#upload_img_component_sheet,#upload_img_component{
  z-index: 10009;
}
</style>
